import Vue from 'vue';
import Vuex from 'vuex';
import { getItem, setItem } from '@/utils/storage.js';

Vue.use(Vuex);

const TOKEN_KEY = 'TOUTIAO_USER';
export default new Vuex.Store({
  state: {
    user: getItem(TOKEN_KEY),
    // user: null,
  },
  mutations: {
    // 定义一个修改state里面的数剧方法
    setUser(state, data) {
      state.user = data;
      // 将存放在vuex里面的token值存放到本地存储里面
      setItem(TOKEN_KEY, state.user);
    },
  },
  actions: {},
  modules: {},
});
